[Match]
Name={{ item.value.interface }}

{% if item.value.address is defined %}
[Address]
{% set addr_cidr = (item.value.address | string + '/' + item.value.netmask | string) | ipaddr('prefix') %}
Address={{ item.value.address }}/{{ addr_cidr }}
{% else %}
[DHCP]
UseDNS={{ (lxc_container_enable_resolved | bool) | ternary('yes', 'no') }}
UseNTP=yes
RouteMetric=20
{% if hostvars[inventory_hostname]['gateway'] is defined %}
UseRoutes=False
{% endif %}

{% endif %}

{% for route in item.value.static_routes | default([]) %}
[Route]
Destination={{ route['cidr'] }}
Gateway={{ route['gateway'] }}
Metric={{ 20 + loop.index }}

{% endfor %}

[Network]
{% if item.value.address is defined %}
{%   set addr_cidr = (item.value.address | string + '/' + item.value.netmask | string) | ipaddr('prefix') %}
Address={{ item.value.address }}/{{ addr_cidr }}
{% else %}
DHCP=yes
{% endif %}
{% if item.value.gateway is defined %}
Gateway={{ item.value.gateway }}
{% endif %}

[Link]
{% if item.value.mtu is defined %}
MTUBytes={{ item.value.mtu }}
{% endif %}
